using System;
using System.Collections.Generic;
using System.Text;
using SharpNeatLib.Evolution;
using SharpNeatLib.NeuralNetwork;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace ParaSharpNeatLib
{
    public class AsyncEvaluation
    {
        private int[] ids;
        private RemoteNetworkEvaluator evaluator;
        private double[] fitness;

        public int[] IDs
        {
            get { return ids; }
            set { ids = value; }
        }
        
        public double[] Fitness
        {
            get { return fitness; }
            set { fitness = value; }
        }
        
        public RemoteNetworkEvaluator Evaluator
        {
            get { return evaluator; }
            set { evaluator = value; }
        }

        public AsyncEvaluation(RemoteNetworkEvaluator evaluator)
        {
            this.evaluator = evaluator;
        }

        public AsyncEvaluation Evaluate(int[] id, List<INetwork> networks, double MIN_GENOME_FITNESS)
        {
            ids = id;

            fitness = evaluator.EvaluateNetworks(networks);

            for (int i = 0; i < fitness.Length; i++)
                if (networks[i] == null)
                    fitness[i] = MIN_GENOME_FITNESS;
                else
                    fitness[i] = Math.Max(fitness[i], MIN_GENOME_FITNESS);

            return this;
        }
    }
}
